﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Honestysoft.Baseframework.WebUI;
using Honestysoft.BaseObject;
using Honestysoft.Financing.Model;
using System.Data;

namespace Honestysoft.Financing.WebUI.Module.WorkflowAcc
{
    public partial class WFOpinionList : BasePage
    {
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                AspNetPager1.PageSize = Globals.PageSize;
                BindControl();
                Bind();
            }
        }
        /// <summary>
        /// 绑定页面控件。
        /// </summary>
        private void BindControl()
        {
            
        }
        /// <summary>
        /// 设置弹出窗体大小
        /// 基类中已自动做控制。默认宽度800，高度600
        /// </summary>
        protected override void SetDialogSize()
        {
            //base.SetDialogSize();
            //重载宽度，高度
            ModalDialogSize.EditHeight = 600;
            ModalDialogSize.EditWidth = 860;
            ModalDialogSize.ViewHeight = 600;
            ModalDialogSize.ViewWidth = 860;
        }
        /// <summary>
        /// 得到查询参数
        /// </summary>
        /// <returns>查询参数</returns>
        private QueryParameters GetQueryParameters()
        {
            QueryParameters queryParameters = new QueryParameters();
            if (txtCode.Text.Trim().Length > 0)
            {
                queryParameters.Add("Code", txtCode.Text, QueryParameters.OperatorType.Like);
            }
            if (txtBatchNo.Text.Trim().Length > 0)
            {
                queryParameters.Add("BatchNo", Convert.ToInt32(txtBatchNo.Text), QueryParameters.OperatorType.Equal);
            }
            return queryParameters;
        }
        /// <summary>
        /// 得到排序参数
        /// </summary>
        /// <returns></returns>
        private OrderParameters GetOrderParameters()
        {
            OrderParameters orderParameters = new OrderParameters();
            //添加排序列
            orderParameters.Add("BatchNo", OrderParameters.OrderDirection.Desc);
            orderParameters.Add("Code");
            return orderParameters;
        }
        /// <summary>
        /// 绑定列表
        /// </summary>
        private void Bind()
        {
            QueryParameters queryParameters = GetQueryParameters();
            OrderParameters orderParameters = GetOrderParameters();
            BaseBusinessLogic<Bu_AuditTable> baseLogic = new BaseBusinessLogic<Bu_AuditTable>();
            int pageCount = 0, recordCount = 0;
            DataTable dtList = baseLogic.GetTablePaging(queryParameters, orderParameters, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, out pageCount, out recordCount);
            dtList.Columns.Add("CurrentNode", typeof(string));
            dtList.Columns.Add("CurrentUser", typeof(string));
            AspNetPager1.RecordCount = recordCount;
            List<string> lsID = new List<string>();
            foreach (DataRow dr in dtList.Rows)
            {
                lsID.Add(dr["ID"].ToString());
            }
            Honestysoft.Workflow.BusinessFacade.WFApply.Work IWork = new Workflow.BusinessFacade.WFApply.Work();
            List<Workflow.Model.WFWorkItem> lsWorks = IWork.GetCurrentWorkItemList(((int)EnumItem.WFBill.AuditTable).ToString(), lsID);
            if (lsWorks != null && lsWorks.Count > 0)
            {
                List<Workflow.Model.WFWorkItem> lsFind = null;
                string node = "", user = "";
                foreach (DataRow dr in dtList.Rows)
                {
                    node = "";
                    user = "";
                    lsFind = lsWorks.FindAll((Workflow.Model.WFWorkItem find) => find.BuDataID == dr["ID"].ToString());
                    if (lsFind != null && lsFind.Count > 0)
                    {
                        foreach (Workflow.Model.WFWorkItem item in lsFind)
                        {
                            if (node != "") { node += ","; user += ","; }
                            node += item.ActTemplateName;
                            user += item.EmployeeName;
                        }
                        dr["CurrentNode"] = node;
                        dr["CurrentUser"] = user;
                    }
                }
            }
            rptList.DataSource = dtList;
            rptList.DataBind();
        }

        protected string GetLinkUrl(string dataId, string subject)
        {
            string script = "";
            if (PageSecurity.Edit)
            {
                if (script.Length > 0) { script += "&nbsp;"; }
                script += "<a href='#' onclick=\"javascript:openwindow('../Audit/AuditTable_Edit.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "','');\" >" + subject + "</a>";
            }
            return script;
        }

        /// <summary>
        /// 得到表格行操作按钮脚本
        /// </summary>
        /// <param name="dataId">记录ID</param>
        /// <param name="buStatus">记录ID</param>
        /// <returns>操作按钮脚本</returns>
        protected string GetButtonScript(string dataId)
        {
            string script = "";
            //if (buStatus == ((int)EnumItem.AuditTableStatus.FAppr).ToString()
            //    || buStatus == ((int)EnumItem.AuditTableStatus.FAppr).ToString())
            //{
            //    if (PageSecurity.Delete)
            //    {
            //        if (script.Length > 0) { script += "&nbsp;"; }
            //        script += ScriptHelper.LinkButton.GetGridDeleteButton(dataId, btnDelete.ClientID);
            //    }
            //}
            if (PageSecurity.Edit)
            {
                if (script.Length > 0) { script += "&nbsp;"; }
                script += "<a href='#' onclick=\"javascript:openwindow('AuditTable_Edit.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "','');\" ><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //if (tableType == "A")
                //{
                //    script += "<a href='#' onclick=\"javascript:openwindow('Bu_AuditTable_View.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "','');\" ><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //   // script += "<a href='Bu_AuditTable_View.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "' target='_blank'><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //}
                //else if (tableType == "B")
                //{
                //    script += "<a href='#' onclick=\"javascript:openwindow('AuditTable_B.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "','');\" ><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //   // script += "<a href='AuditTable_B.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "' target='_blank'><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //}
                //else if (tableType == "C")
                //{
                //    script += "<a href='#' onclick=\"javascript:openwindow('AuditTable_C.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "','');\" ><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //    //script += "<a href='AuditTable_C.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "' target='_blank'><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //}
            }
            return script;
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            Bind();
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            Bind();
        }
    }
}